gtkgstsink: Use video_frame_free also for the GL path
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>
Mon, 25 Jan 2021 21:38:45 +0000 (22:38 +0100)
committerJan Alexander Steffens (heftig) <jan.steffens@gmail.com>
Tue, 26 Jan 2021 19:30:47 +0000 (20:30 +0100)
The video frame needs to stay mapped while the texture is in use.

Avoid using g_memdup because the structure is not supposed to be moved.

modules/media/gtkgstsink.c

index 7375525c600b796e929bb0842063bbc358bb85be..c546ec7ff6433a4e9d3cdaf37c2b2ffb5bea720e 100644 (file)
@@ -259,44 +259,43 @@ gtk_gst_sink_texture_from_buffer (GtkGstSink *self,
                                   GstBuffer  *buffer,
                                   double     *pixel_aspect_ratio)
 {
-  GstVideoFrame frame;
+  GstVideoFrame *frame = g_new (GstVideoFrame, 1);
   GdkTexture *texture;
 
   if (self->gdk_context &&
-      gst_video_frame_map (&frame, &self->v_info, buffer, GST_MAP_READ | GST_MAP_GL))
+      gst_video_frame_map (frame, &self->v_info, buffer, GST_MAP_READ | GST_MAP_GL))
     {
       texture = gdk_gl_texture_new (self->gdk_context,
-                                    *(guint *) frame.data[0],
-                                    frame.info.width,
-                                    frame.info.height,
-                                    (GDestroyNotify) gst_buffer_unref,
-                                    gst_buffer_ref (buffer));
+                                    *(guint *) frame->data[0],
+                                    frame->info.width,
+                                    frame->info.height,
+                                    (GDestroyNotify) video_frame_free,
+                                    frame);
 
-     *pixel_aspect_ratio = ((double) frame.info.par_n) / ((double) frame.info.par_d);
-
-      gst_video_frame_unmap (&frame);
+      *pixel_aspect_ratio = ((double) frame->info.par_n) / ((double) frame->info.par_d);
     }
-  else if (gst_video_frame_map (&frame, &self->v_info, buffer, GST_MAP_READ))
+  else if (gst_video_frame_map (frame, &self->v_info, buffer, GST_MAP_READ))
     {
       GBytes *bytes;
 
-      bytes = g_bytes_new_with_free_func (frame.data[0],
-                                          frame.info.height * frame.info.stride[0],
+      bytes = g_bytes_new_with_free_func (frame->data[0],
+                                          frame->info.height * frame->info.stride[0],
                                           (GDestroyNotify) video_frame_free,
-                                          g_memdup (&frame, sizeof (frame)));
-      texture = gdk_memory_texture_new (frame.info.width,
-                                        frame.info.height,
-                                        gtk_gst_memory_format_from_video (GST_VIDEO_FRAME_FORMAT (&frame)),
+                                          frame);
+      texture = gdk_memory_texture_new (frame->info.width,
+                                        frame->info.height,
+                                        gtk_gst_memory_format_from_video (GST_VIDEO_FRAME_FORMAT (frame)),
                                         bytes,
-                                        frame.info.stride[0]);
+                                        frame->info.stride[0]);
       g_bytes_unref (bytes);
 
-     *pixel_aspect_ratio = ((double) frame.info.par_n) / ((double) frame.info.par_d);
+      *pixel_aspect_ratio = ((double) frame->info.par_n) / ((double) frame->info.par_d);
     }
   else
     {
       GST_ERROR_OBJECT (self, "Could not convert buffer to texture.");
       texture = NULL;
+      g_free (frame);
     }
 
   return texture;